# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2024/10/19
desc: 
sample: 
"""
import csv

import pytest
import requests


# def getcsvlist():
#     idlist=[]
#     with open('id.csv',encoding='utf-8') as f:
#         csv_reader = csv.reader(f)
#         next(csv_reader)
#         for line in csv_reader:
#             idlist.append(line)
#     return idlist
from utils import getcsvlist, getcsvlist_dict, get_excel_to_list, get_excel_to_list_dict

# def getcsvlist_dict():
#     list = []
#     with open('id.csv', encoding="utf-8") as f:
#         csv_reader = csv.DictReader(f)
#         for line in csv_reader:
#             list.append(line)
#     return list

# print(getcsvlist_dict())

host = 'http://121.11.97.201:9088/pinter/com/'
excel_list = get_excel_to_list('case.xlsx')

@pytest.mark.run(order=2)
@pytest.mark.flaky(reruns=3,reruns_delay=2) #延迟2秒 再重试 最多重试三次
@pytest.mark.parametrize("case_name,username,pwd,msg",excel_list,ids=[item[0] for item in excel_list]) #list(list)
def test_getSku(case_name,username,pwd,msg):
   post_params = {'userName': username, 'password': pwd}
   response = requests.post(url=f'{host}login', data=post_params)
   assert response.status_code == 200
   res_dict = response.json()
   assert res_dict['message'] == msg


excel_list = get_excel_to_list_dict('case.xlsx')

@pytest.mark.run(order=1)
@pytest.mark.flaky(reruns=3,reruns_delay=2) #延迟2秒 再重试 最多重试三次
@pytest.mark.parametrize("params",excel_list,ids=[item.get('case') for item in excel_list]) #list(dict)
def test_login(params):
   post_params = {'userName': params.get('usr'), 'password': params.get('psw')}
   response = requests.post(url=f'{host}login', data=post_params)
   assert response.status_code == 200
   res_dict = response.json()
   assert res_dict['message'] == params.get('message')

data_1 = [x for x in range(10)]
data_2 = [x for x in range(100)]
@pytest.mark.parametrize('a', data_1)
@pytest.mark.parametrize('b', data_2)
def test_parametrize_1(a, b):
 #sleep(0.01)
 print(f'笛卡尔积 测试数据为 ： {a}，{b}')